package com.gitee.cirnochat.chatai.model.enums.aimessage;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.gitee.cirnochat.common.model.enums.BaseEnum;
import lombok.Getter;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.SystemMessage;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.content.Media;

/**
 * 角色枚举类
 */
@Getter
public enum ChatRoleType implements BaseEnum<Integer>, AIMessageBuilder {
    USER(0),
    AI(1),
    SYSTEM(2),
    ;

    @JsonValue
    @EnumValue
    private final Integer value;

    ChatRoleType(Integer value) {
        this.value = value;
    }

    public static ChatRoleType fromValue(Integer value) {
        for (ChatRoleType chatRoleType : ChatRoleType.values()) {
            if (chatRoleType.getValue().equals(value)) {
                return chatRoleType;
            }
        }
        return null;
    }

    @Override
    public Message buildMessage(String content, Media... media) {
        switch (this) {
            case USER -> {
                return UserMessage.builder().text(content).media(media).build();
            }
            case SYSTEM -> {
                return new SystemMessage(content);
            }
            case AI -> {
                return new AssistantMessage(content);
            }
        }
        return null;
    }

}
